package org.mydba.info;

/**
 * Represents preparedStatement.update() execution statistics.
 *
 * @since 1.0
 */
public class UpdateStatistic {
    private long numberOfRows;
    private long startTimeNs;
    private long totalUpdateDuration;

    public UpdateStatistic(final long startTimeNs, final long numberOfRows, final long updateDuration) {
        this.startTimeNs = startTimeNs;
        this.numberOfRows = numberOfRows;
        this.totalUpdateDuration = updateDuration;
    }

    public long getNumberOfRows() {
        return numberOfRows;
    }

    public long getStartTimeNs() {
        return startTimeNs;
    }

    public long getTotalUpdateDuration() {
        return totalUpdateDuration;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        UpdateStatistic that = (UpdateStatistic) o;

        if (numberOfRows != that.numberOfRows) {
            return false;
        }

        return totalUpdateDuration == that.totalUpdateDuration;
    }

    @Override
    public int hashCode() {
        int result = (int) (numberOfRows ^ (numberOfRows >>> 32));
        result = 31 * result + (int) (totalUpdateDuration ^ (totalUpdateDuration >>> 32));
        return result;
    }

    public void update(final long numberOfRows, final long updateDuration) {
        this.numberOfRows += numberOfRows;
        this.totalUpdateDuration += updateDuration;
    }
}
